package com.sina.shop.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    // 存储一个键值对
    public void setValue(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    // 获取一个值
    public Object getValue(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    // 删除一个键
    public void deleteKey(String key) {
        redisTemplate.delete(key);
    }
}